package com.slmxz.tms.core.handler;

import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.MessageSource;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.support.RequestContextUtils;

import java.util.Locale;

/**
 * 国际化处理类
 * @Author：albert
 * @Date：2025/7/12 21:28
 */
@Component
public class MessageSourceHandler {

    @Resource
    private HttpServletRequest request;

    @Resource
    private MessageSource messageSource;

    public String getMessage(String messageKey) {
        return getMessage(messageKey, null);
    }

    public String getMessage(String messageKey, Object[] args) {
        return messageSource.getMessage(messageKey, args, RequestContextUtils.getLocale(request));
    }

    public String getMessage(String messageKey, Object[] args, Locale locale) {
        return messageSource.getMessage(messageKey, args, locale);
    }
}
